package com.sfac.springboot.modules.common.controller;

import com.sfac.springboot.modules.common.vo.ImageType;
import com.sfac.springboot.modules.common.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jzq
 * @date 2022/8/23 14:57
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/api")
public class EnumDictionaryController {

    public static Map<String, Class> map = new HashMap() {{
        put("imageType", ImageType.class);
        put("resultStatus", Result.ResultStatus.class);
    }};


    /**
     * localhost/api/dictionary/imageType
     *
     * @param enumName
     * @return
     */
    @GetMapping(value = "/dictionary/{enumName}")
    public List<Object> enumDictionary(@PathVariable String enumName) {
        Class clazz = map.get(enumName);
        if (clazz != null) {
            try {
                Method method = clazz.getDeclaredMethod("values");
                Object[] objects = (Object[]) method.invoke(null);
                return Arrays.asList(objects);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
